#include "audioVoencodetask.h"
#include "audioinfoinput.h"
#include "mainwindow.h"
#include <QApplication>
#include <QAudioInput>
#include <QAudioOutput>
#include <QFile>
#include "audiodecodetask.h"
#include "audioinfooutput.h"
#include "networkimpl.h"
#include "qDebug2Logcat.h"
int main(int argc, char *argv[])
{
    installLogcatMessageHandler("yourLogTag");

    av_register_all();

    qDebug(QString::fromUtf8("初始化音频格式信息1...").toLocal8Bit().data());
    QAudioFormat    m_format;
    m_format.setSampleRate(8000);
    m_format.setChannelCount(1);
    m_format.setSampleSize(16);
    m_format.setSampleType(QAudioFormat::UnSignedInt);
    m_format.setByteOrder(QAudioFormat::LittleEndian);
    m_format.setCodec("audio/pcm");


    OpenSl_Engine openSlEngine;

    qDebug(QString::fromUtf8("启动音频播放2...").toLocal8Bit().data());
    AudioInfoOutPut m_audioOutInfo(&openSlEngine);
    m_audioOutInfo.start();

    QAudioOutput   m_audioOutput(m_format);//m_audioOutput.start(&m_audioOutInfo);

//    qDebug(QString::fromUtf8("连接到服务器...").toLocal8Bit().data());
//    qDebug(QString("tcpClient.Connet begin:").toLocal8Bit().data());
//    NetWorkImpl tcpClient;   //网络数据发送到解码任务
//    tcpClient.recv_handler(&m_audioOutInfo);
//    tcpClient.Connet("182.92.177.100",9889);//连接服务器
//    qDebug(QString("tcpClient.Connet end:").toLocal8Bit().data());


//    qDebug(QString::fromUtf8("启动解码任务...").toLocal8Bit().data());
//    AudioDecodeTask *pAdioDecodeTask = new AudioDecodeTask(&m_audioOutInfo);
//    pAdioDecodeTask->activate();//启动任务线程

//    qDebug(QString::fromUtf8("连接到服务器...").toLocal8Bit().data());
//    qDebug(QString("tcpClient.Connet begin:").toLocal8Bit().data());
//    NetWorkImpl tcpClient;   //网络数据发送到解码任务
//    tcpClient.recv_handler(pAdioDecodeTask);
//    tcpClient.Connet("182.92.177.100",9889);//连接服务器
//    qDebug(QString("tcpClient.Connet end:").toLocal8Bit().data());

//    qDebug(QString::fromUtf8("启动编码任务...").toLocal8Bit().data());
//    AudioEncodeTask *pAdioEncodeTask = new AudioEncodeTask(&tcpClient);
//    pAdioEncodeTask->activate();//启动任务线程

    qDebug(QString::fromUtf8("启动音频采集3...").toLocal8Bit().data());
    AudioInfoInPut  m_audioInInfo(&openSlEngine,&m_audioOutInfo);//pAdioEncodeTask//
    m_audioInInfo.start();

    QAudioInput   m_audioInput(m_format);//m_audioInput.start(&m_audioInInfo);

    QApplication a(argc, argv);
    qDebug(QString::fromUtf8("启动界面4").toLocal8Bit().data());
    MainWindow w(&m_audioInInfo,&m_audioInput,&m_audioOutInfo,&m_audioOutput);
    w.show();

    return a.exec();
}
